package com.session.redis.controller;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpSession;

/**
 * SessionController
 *
 * @author: chenfenghai
 * @version: 1.0
 * @date: 2021-01-20 14:33
 */
@RestController
public class SessionController {

    @GetMapping("/test")
    public String test(){
        return "test";
    }

    @Value("${server.port}")
    String port;

    @GetMapping("/save/{name}")
    public String saveName(@PathVariable("name")String name, HttpSession session) {
        session.setAttribute("name", name);
        return port;
    }

    @GetMapping("/get")
    public String getName(HttpSession session) {
        return port + "：" + session.getAttribute("name");
    }
}
